<?php
class AccountController
{
	private $gfc_cookie_name;
	
	public function __construct()
	{
		$this->gfc_cookie_name = ConfigParser::get('google_friend_connect', 'cookie_name');
	}
	
	public function isLogined()
	{
		session_set_cookie_params (0,'/',ConfigParser::get('session','domain'));
		session_start();
		if(isset($_SESSION['id']))
		{
			//return true;
		}
		if(isset($_COOKIE[$this->gfc_cookie_name])&&!empty($_COOKIE[$this->gfc_cookie_name]))
		{
			$user_model = new UserModel();
			$result = $user_model->getUserFromGoogleFriendConnect($_COOKIE[$this->gfc_cookie_name]);
			if(!empty($result))
			{
				if($user_model->setUserToDb($result)===true)
				{
					$_SESSION['id'] = $result['id'];
					foreach($_COOKIE as $key=>$value)
					{
						setcookie($key,$value,time() + ConfigParser::get('cookie','ttl'),'/',ConfigParser::get('cookie','domain'));
					}
					return true;
				}
			}
		}
		return false;
	}
	
	public function loginAction()
	{
		$this->isLogined();
		$v = array();
		Common::output($v,'account_login');
		return true;
	}
}
?>